﻿<UserControl x:Class="BizControl.Presentation.StickyNotesModule.Views.StickyNotesView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:csla="clr-namespace:Csla.Xaml;assembly=Csla.Xaml"
             xmlns:converters="clr-namespace:BizControl.Presentation.StickyNotesModule.Converters">
    <UserControl.Resources>
        <DataTemplate x:Key="NoteInList">
            <Border BorderThickness="2" BorderBrush="DarkGray"
                    CornerRadius="2" HorizontalAlignment="Center" MinWidth="50" MinHeight="50">
                <Border.Background>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                        <GradientStop Color="#FFECEDB1" Offset="0"/>
                        <GradientStop Color="#FFE9ED22" Offset="0.5"/>
                        <GradientStop Color="#FFF8BF0A" Offset="1"/>
                    </LinearGradientBrush>
                </Border.Background>
                <Border.Margin>
                    <Binding>
                        <Binding.RelativeSource>
                            <RelativeSource AncestorLevel="1" AncestorType="{x:Type ListBoxItem}" Mode="FindAncestor" />
                        </Binding.RelativeSource>
                        <Binding.Converter>
                            <converters:IndexToMarginValueConverter />
                        </Binding.Converter>
                    </Binding>
                </Border.Margin>
                <Border.RenderTransform>
                    <RotateTransform CenterX="25" CenterY="4">
                        <RotateTransform.Angle>
                            <Binding>
                                <Binding.RelativeSource>
                                    <RelativeSource AncestorLevel="1" AncestorType="{x:Type ListBoxItem}" Mode="FindAncestor"/>
                                </Binding.RelativeSource>
                                <Binding.Converter>
                                    <converters:IndexToAngleConverter />
                                </Binding.Converter>
                            </Binding>
                        </RotateTransform.Angle>
                    </RotateTransform>
                </Border.RenderTransform>
                <StackPanel>
                    <Grid>
                        <!--IsEnabled="{Binding Path=CanSave}"-->
                        <Button x:Name="SaveButton" HorizontalAlignment="Left" ToolTip="Сохранить"
                                IsEnabled="False"
                                Template="{StaticResource OkButtonTemplate}" />
                        <!--<csla:TriggerAction TargetControl="{Binding ElementName=SaveButton}" MethodName="Save"/>-->
                        <Button HorizontalAlignment="Right" ToolTip="Свернуть"
                                Template="{StaticResource RemoveButtonTemplate}" Click="MinimizeButton_Click" />
                    </Grid>
                    <StackPanel>
                        <TextBlock Foreground="Black" HorizontalAlignment="Center" FontSize="12" FontFamily="Century Gothic">
                        <TextBlock.Text>
                            <Binding Path="CreatedOn">
                                <Binding.Converter>
                                    <converters:MonthNumberToNameValueConverter />
                                </Binding.Converter>
                            </Binding>
                        </TextBlock.Text>
                        </TextBlock>
                        <TextBlock Foreground="Black" HorizontalAlignment="Center" FontSize="18" FontFamily="Century Gothic">
                            <TextBlock.Text>
                                <Binding Path="CreatedOn">
                                    <Binding.Converter>
                                        <converters:DateStringToDayNumberConverter />
                                    </Binding.Converter>
                                </Binding>
                            </TextBlock.Text>
                        </TextBlock>
                        <TextBox Foreground="Black" HorizontalAlignment="Center" FontWeight="Bold"
                                 Text="{Binding Name, Mode=TwoWay}" TextWrapping="Wrap" MaxWidth="150" MaxHeight="100"
                                 ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.CanContentScroll="True"
                                 FontSize="12" FontFamily="Century Gothic" />
                    </StackPanel>
                    <StackPanel Width="150" Margin="20">
                        <StackPanel.Style>
                            <Style>
                                <Style.Triggers>
                                    <DataTrigger 
                                        Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}}" 
                                        Value="False">
                                        <Setter Property="StackPanel.Visibility" Value="Collapsed" />
                                        <Setter Property="StackPanel.Margin" Value="0,0,0,0" />
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </StackPanel.Style>
                        <TextBox FontSize="12" Text="{Binding Path=Content, UpdateSourceTrigger=PropertyChanged}" 
                                 MaxHeight="200" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.CanContentScroll="True"
                                 TextWrapping="Wrap" BorderThickness="0" Background="Transparent" AcceptsReturn="True" >
                        </TextBox>
                    </StackPanel>
                </StackPanel>
            </Border>
        </DataTemplate>
    </UserControl.Resources>
    
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="30" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <ToolBar>
            <Button HorizontalAlignment="Left" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch"
                    Width="25" Height="25" ToolTip="Добавить заметку"
                    Command="{Binding Path=AddNoteCommand}" Content="{StaticResource PlusPath}" />
        </ToolBar>
        <ListBox Grid.Row="1" Name="NotesListBox"
                 ItemTemplate="{StaticResource NoteInList}" HorizontalContentAlignment="Right"  ItemsSource="{Binding Model}" Margin="5"
                 BorderThickness="0" Background="Transparent" ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
                 HorizontalAlignment="Right" Width="250">
            <ListBox.Resources>
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/>
                <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent"/>
            </ListBox.Resources>
        </ListBox>
    </Grid>
</UserControl>
